﻿using System;
using System.Globalization;

namespace Microsoft.International.Formatters
{

    /// <summary>
    /// Internal static class which countains list of extension methods available for formatters.
    /// </summary>
    internal static class Extensions
    {

        /// <summary>
        /// Get the unit of a Int32 value.
        /// </summary>
        /// <param name="value">Get the unit of this Int32 value.</param>
        /// <example>Example: 24.GetUnit() will return 4</example>
        /// <returns>Return the unit from the specified value</returns>
        internal static Int32 GetUnit(this Int32 value)
        {
            String strValue = value.ToString(CultureInfo.CurrentCulture);
            return Int32.Parse(strValue.Substring(strValue.Length - 1, 1), CultureInfo.CurrentCulture);
        }

        /// <summary>
        /// Get the ten of a Int32 value.
        /// </summary>
        /// <param name="value">Get the ten of this Int32 value.</param>
        /// <example>Example: 24.GetTen() will return 20</example>
        /// <returns>Return the ten from the specified value</returns>
        internal static Int32 GetTen(this Int32 value)
        {
            // The value cannot be less than 10.
            if (value <= 10)
                return 0;

            String strValue = value.ToString(CultureInfo.CurrentCulture);
            return Int32.Parse(strValue.Substring(strValue.Length - 2, 1), CultureInfo.CurrentCulture) * 10;
        }

        /// <summary>
        /// Get if a specified value is between specified bounds.
        /// </summary>
        /// <param name="value">Value to compare</param>
        /// <param name="down">Minimal bound</param>
        /// <param name="up">Maximal bound</param>
        /// <returns>Return true if the specified value is between bounds ; false else.</returns>
        internal static Boolean Between(this Int32 value, Int32 down, Int32 up)
        {
            return (value >= down && value <= up);
        }

        /// <summary>
        /// Get is the specified char is a vowel
        /// </summary>
        /// <param name="letter">Specified char</param>
        /// <returns>Return if the specified char is a vowel.</returns>
        internal static Boolean IsVowel(this Char letter)
        {
            Char[] vowels = new Char[] { 'a', 'e', 'i', 'o', 'u', 'y' };
            foreach (Char l in vowels)
                if (l.Equals(letter))
                    return true;

            return false;
        }

    }

}